<template>
  <view class="member-list">
    <template v-for="v in modelValue" :key="v.id">
      <MemberItem :item="v" @click="toPersonCard(v.memberLeadingId)" />
    </template>
  </view>
</template>

<script setup lang="ts">
  import { type PropType } from 'vue';
  import { type IMemberItem } from '@/api/mine/types';
  import MemberItem from '../../components/memberItem/index.vue';
  import { navigateTo, redirectTo } from '@/router';
  import { propTypes } from '@/utils/propTypes';
  import { useUserStoreWithOut } from '@/store/modules/user';
  import { Toast } from '@/utils';

  const props = defineProps({
    modelValue: Array as PropType<IMemberItem[]>,
    isToDetails: propTypes.bool.def(false),
  });

  const { cocInfo } = useUserStoreWithOut();

  function toPersonCard(id: number) {
    if (props.isToDetails) {
      cocInfo.id === id
        ? redirectTo({ name: 'personCard', options: {} })
        : navigateTo({
            name: 'personCard',
            options: {
              id,
            },
          });
    } else {
      Toast('人脉详情暂未开放，查看请联系管理员');
    }
  }
</script>

<style lang="scss" scoped>
  .member {
    &-list {
      padding-top: 20rpx;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
    }
  }
</style>
